<!DOCTYPE html>
<html lang="en" >
<head>
    <meta charset="UTF-8">
    <title>复制文件</title>
    <script src="js/jQuery.js"></script>
    <link rel="stylesheet" href="admin/css/pearCommon.css" />
    <link rel="stylesheet" href="component/layui/css/layui.css" />
    <script src="component/layui/layui.js"></script>
    <SCRIPT src="js/common.js"></SCRIPT>
    <style>
        .layui-form-label:after{
            content:"*";
            color:red;
            position: absolute;
            top:5px;
            left:15px;
        }
    </style>
</head>
<body>
<form class="layui-form" action="">
    <div class="mainBox">
        <div class="main-container">
            <div class="main-container">
                <div class="layui-form-item" style="display: none">
                    <label class="layui-form-label">文件id</label>
                    <div class="layui-input-block">
                        <input type="text" id="fileId" class="fileId" readonly="readonly" name="fileId" lay-verify="required" autocomplete="off" value=""  class="layui-input">
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">文件夹</label>
                    <div class="layui-input-block">
                        <select name="fileName" id="fileName" class=" role layui-input" autocomplete="off" >
                            <option value='' style='font-weight: bold;' selected>根目录</option>
                        </select>
                    </div>
                </div>
            </div>
        </div>
    </div>

    <div class="bottom">
        <div class="button-container">
            <button type="submit" class="layui-btn layui-btn-sm" lay-submit="" lay-filter="user-save">
                <i class="layui-icon layui-icon-ok"></i>
                提交
            </button>
            <button type="reset" class="layui-btn layui-btn-primary layui-btn-sm">
                <i class="layui-icon layui-icon-refresh"></i>
                重置
            </button>
        </div>
    </div>
</form>
<script>
    let obsFile={};
    obsFile.path=sessionStorage.getItem("sharedPath");
    obsFile.type = "文件夹";
    $.ajax({
        url: sessionStorage.getItem("rootPath")+ "/files/selectSharedFilesList",
        method: "post",
        dataType: "json",
        contentType: 'application/json;charset=utf-8',
        data: JSON.stringify(obsFile),
        async:false,
        success: function (data) {
            $(data.data).each(function (i, n) {
                let newPath = n.path.split("/");
                newPath.shift();
                let sPath = newPath.join("/");
                $("#fileName").append("<option value='" + n.path + "' style='font-weight: bold;'>" +  sPath + "</option>");
            });
            layui.use('form', function () {
                var form = layui.form; //只有执行了这一步，部分表单元素才会自动修饰成功
                form.render('select');
            })
        },
        error: function (XMLHttpRequest, textStatus, errorThrown) {
            console.log("失败" + XMLHttpRequest.status + ":" + textStatus + ":" + errorThrown);
        }
    })
    layui.use(['pearHash','form','jquery'],function(){
        var form = layui.form,layer=layui.layer;
        var $ = layui.jquery;
        var pearHash = layui.pearHash;
        //自定义验证规则
        form.verify({
            required: function(value,elem){
                if(!value){
                    return '必填项不能为空！'
                }
            }
        });
        form.on('submit(user-save)', function(data){
            //layui表单提交方式，根据name属性提交
            //name值跟属性名一样
            let arr = $("#fileId").val().split(",");
            var obsFile = {};
            obsFile.fileId=arr[0];
            //要处理一下名字
            obsFile.fileName=arr[1];
            if ($("#fileName").val() == null || $("#fileName").val() == ""){
                obsFile.path=$("#fileName").val()+arr[2];
            } else {
                obsFile.path=$("#fileName").val()+"/"+arr[2];
            }
            obsFile.userId=sessionStorage.getItem("id");
            obsFile.sharedId = sessionStorage.getItem("sharedFileId");
            $.ajax({
                url: sessionStorage.getItem("rootPath") + "/sharedFiles/move",
                data:JSON.stringify(obsFile),
                dataType:'json',
                contentType: 'application/json;charset=utf-8',
                type:'post',
                async: false, // 使用同步操作
                timeout : 50000, //超时时间：50秒
                success:function(res){
                    if(res==1){
                        layer.msg("移动成功!",{icon:1,time:1000},function(){
                            parent.getSharedFilesListM();
                            parent.layer.close(parent.layer.getFrameIndex(window.name));//关闭当前页
                        });
                    }else if(res==2){
                        layer.msg("移动失败！",{icon:0,time:1000});
                    }
                },
                error: function (XMLHttpRequest, textStatus, errorThrown) {
                    console.log("失败" + XMLHttpRequest.status + ":" + textStatus + ":" + errorThrown);
                }
            })
            return false;
        });
    })
</script>
<script>
</script>
</body>
</html>